home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / bin / localepurge < prev    next >
Text File  |  2006-01-09  |  7KB  |  236 lines

  1. #!/bin/sh
  2.  
  3. # Deleting all locale files on system
  4. # *not* listed in /etc/locale.nopurge
  5.  
  6. LOCALEDIRS="/usr/share/locale /usr/local/share/locale /usr/kde/?.?/share/locale /opt/sun-jdk-*/jre/lib/locale /opt/sun-jre-bin-*/lib/locale /usr/lib/locale"
  7. MANPAGEDIRS="/usr/share/man /usr/man /usr/local/share/man /usr/kde/?.?/share/man /usr/kde/?.?/man /opt/sun-jdk-*/man /opt/sun-jre-bin-*/man"
  8. LOCALELIST="/var/cache/localepurge/localelist"
  9. VERSION="0.5"
  10.  
  11. LOCALETOTAL=0
  12. MANTOTAL=0
  13.  
  14. set -e
  15.  
  16. if [ "$1" = "-debug" ] || [ "$1" = "-d" ] \
  17.     || [ "$2" = "-debug" ] || [ "$2" = "-d" ] \
  18.     || [ "$3" = "-debug" ] || [ "$3" = "-d" ] \
  19.     || [ "$4" = "-debug" ] || [ "$4" = "-d" ] \
  20.     || [ "$5" = "-debug" ] || [ "$5" = "-d" ]; then
  21. set -x
  22. fi
  23.  
  24. if [ "`grep -x ^NOCOLOR /etc/locale.nopurge`" ] \
  25.     || [ "$1" = "-nocolor" ] || [ "$1" = "-nc" ] \
  26.     || [ "$2" = "-nocolor" ] || [ "$2" = "-nc" ] \
  27.     || [ "$3" = "-nocolor" ] || [ "$3" = "-nc" ] \
  28.     || [ "$4" = "-nocolor" ] || [ "$4" = "-nc" ] \
  29.     || [ "$5" = "-nocolor" ] || [ "$5" = "-nc" ]; then
  30.     NOCOLOR=yes
  31. fi
  32.  
  33. if [[ ${NOCOLOR} == yes ]]; then
  34.     unset GOOD WARN BAD NORMAL HILITE BRACKET BOLD
  35. else
  36.     GOOD=$'\e[32;01m'
  37.     WARN=$'\e[33;01m'
  38.     BAD=$'\e[31;01m'
  39.     NORMAL=$'\e[0m'
  40.     HILITE=$'\e[36;01m'
  41.     BRACKET=$'\e[34;01m'
  42.     BOLD=$'\e[1m'
  43. fi
  44. eerror () {
  45.     echo -e " ${BAD}*${NORMAL} $*"
  46. }
  47.  
  48. ewarn () {
  49.     echo -e " ${WARN}*${NORMAL} $*"
  50. }
  51.  
  52. einfo () {
  53.     echo -e " ${GOOD}*${NORMAL} $*"
  54. }
  55. etab () {
  56.     echo -e " ${GOOD}*${NORMAL} $*"
  57. }
  58.  
  59. ayuda () {
  60.     echo "${HILITE}localepurge${NORMAL} for ${BOLD}Gentoo Linux${NORMAL} ${BRACKET}[${NORMAL} ${GOOD}${VERSION}${NORMAL} ${BRACKET}]${NORMAL}"
  61.     echo -e " " "by bass@gentoo.org"
  62.     echo
  63.     einfo "Remember that you must edit /etc/locale.nopurge"
  64.     echo
  65.     einfo "Usage: `basename $0` [options]"
  66.     echo
  67.     etab "${BOLD}-help (-h)     ${NORMAL}  : show this help."
  68.     etab "${BOLD}-debug (-d)    ${NORMAL}  : debug mode."
  69.     etab "${BOLD}-verbose (-v)  ${NORMAL}  : verbose mode."
  70.     etab "${BOLD}-nocolor (-nc) ${NORMAL}  : no color mode."
  71.     etab "${BOLD}-version    ${NORMAL}  : show version."
  72.     echo
  73. }
  74.  
  75. version () {
  76.     einfo "${BRACKET}[${NORMAL} ${GOOD}${VERSION}${NORMAL} ${BRACKET}]${NORMAL}"
  77. }
  78. if [ "$1" = "-help" ] || [ "$1" = "-h" ] \
  79.     || [ "$2" = "-help" ] || [ "$2" = "-h" ] \
  80.     || [ "$3" = "-help" ] || [ "$3" = "-h" ] \
  81.     || [ "$4" = "-help" ] || [ "$4" = "-h" ] \
  82.     || [ "$5" = "-help" ] || [ "$5" = "-h" ]; then
  83.     ayuda
  84.     exit 0
  85. fi
  86.  
  87. if [ "$1" = "-version" ] \
  88.     || [ "$2" = "-version" ]  \
  89.     || [ "$3" = "-version" ]  \
  90.     || [ "$4" = "-version" ]  \
  91.     || [ "$5" = "-version" ] ; then
  92.     version
  93.     exit 0
  94. fi
  95.  
  96. if [ "`grep -x ^SHOWFREEDSPACE /etc/locale.nopurge`" ]; then
  97.     SHOWFREEDSPACE=enabled
  98. fi
  99.  
  100. if [ "`grep -x ^VERBOSE /etc/locale.nopurge`" ] \
  101.     || [ "$1" = "-verbose" ] || [ "$1" = "-v" ] \
  102.     || [ "$2" = "-verbose" ] || [ "$2" = "-v" ] \
  103.     || [ "$3" = "-verbose" ] || [ "$3" = "-v" ] \
  104.     || [ "$4" = "-verbose" ] || [ "$4" = "-v" ] \
  105.     || [ "$5" = "-verbose" ] || [ "$5" = "-v" ]; then
  106.     VERBOSE=enabled
  107. fi
  108.  
  109. # Do nothing and report why if no valid configuration file exists:
  110.  
  111. if [ ! -f /etc/locale.nopurge ]
  112.     then
  113.         eerror " No /etc/locale.nopurge file present, exiting ..."
  114.         exit 0
  115.     else
  116.         if [ "`grep -x ^NEEDSCONFIGFIRST /etc/locale.nopurge`" ]
  117.             then
  118.                 echo ""
  119.                 einfo "    You have to configure \"/etc/locale.nopurge\" "
  120.                 echo ""
  121.                 einfo "    to make $0 actually start to function."
  122.                 echo ""
  123.                 einfo "    Nothing to be done, exiting ..."
  124.                 echo ""
  125.                 exit 0
  126.         fi
  127. fi
  128.  
  129. # Getting rid of superfluous locale files in $LOCALEDIR:
  130.  
  131. purgelocale () {
  132.     local LOCALEDIR="$1"
  133. if [ -d $LOCALEDIR ]; then
  134.  
  135.     if [ "$SHOWFREEDSPACE" = "enabled" ]; then
  136.         LOCALEBEFORE=$(df -P $LOCALEDIR | awk '{if ( NR==2 ) { print $3 }}')
  137.     fi
  138.  
  139.     if [ "$VERBOSE" = "enabled" ]; then
  140.         einfo "localepurge: processing locale files in ${LOCALEDIR} ..."
  141.         for LOCALE in `/bin/ls ${LOCALEDIR}` 
  142.          do
  143.           if [ ! "`grep -x ^${LOCALE} /etc/locale.nopurge`" ] && \
  144.              [ "`grep -x ^${LOCALE} ${LOCALELIST}`" ]; then
  145.             if [ -d ${LOCALEDIR}/${LOCALE}/LC_MESSAGES ]; then
  146.                  /bin/rm -vf `find ${LOCALEDIR}/${LOCALE} -type f`
  147.             fi
  148.           fi
  149.          done
  150.     else
  151.         for LOCALE in `/bin/ls ${LOCALEDIR}`
  152.          do
  153.           if [ ! "`grep -x ^${LOCALE} /etc/locale.nopurge`" ] && \
  154.              [ "`grep -x ^${LOCALE} ${LOCALELIST}`" ]; then
  155.             if [ -d ${LOCALEDIR}/${LOCALE}/LC_MESSAGES ]; then
  156.                  /bin/rm -f `find ${LOCALEDIR}/${LOCALE} -type f`
  157.             fi
  158.           fi
  159.          done
  160.     fi
  161.  
  162.     if [ "$SHOWFREEDSPACE" = "enabled" ]; then
  163.         LOCALEAFTER=$(df -P $LOCALEDIR | awk '{if ( NR==2 ) { print $3 }}')
  164.         LOCALESUM=$(($LOCALEBEFORE - $LOCALEAFTER))
  165.     LOCALETOTAL=$(($LOCALETOTAL + $LOCALESUM))
  166.     if [ ! $LOCALEBEFORE = $LOCALEAFTER ]; then
  167.             einfo "localepurge: Disk space freed in $LOCALEDIR: ${BOLD}"$LOCALESUM"K${NORMAL}"
  168.         fi
  169.     fi
  170. fi
  171. }
  172.  
  173. # Getting rid of localized man pages in $MANPAGEDIR
  174.  
  175. purgeman () {
  176.     local MANPAGEDIR="$1"
  177. if [ -d $MANPAGEDIR ] && [ "`grep -x ^MANDELETE /etc/locale.nopurge`" ]; then
  178.  
  179.     if [ "$SHOWFREEDSPACE" = "enabled" ]; then
  180.         MANBEFORE=$(df -P $MANPAGEDIR | awk '{if ( NR==2 ) { print $3 }}')
  181.         fi
  182.  
  183.     if [ "$VERBOSE" = "enabled" ]; then
  184.         einfo "localepurge: processing man pages in ${MANPAGEDIR} ..."
  185.         for LOCALE in `/bin/ls ${MANPAGEDIR} | grep -v ^man[1-9]`
  186.          do
  187.           if [ ! "`grep -x ^${LOCALE} /etc/locale.nopurge`" ] && \
  188.              [ "`grep -x ^${LOCALE} ${LOCALELIST}`" ]; then
  189.             if [ -d ${MANPAGEDIR}/${LOCALE} ]; then
  190.                 /bin/rm -vf `find ${MANPAGEDIR}/${LOCALE} -type f`
  191.             fi
  192.           fi
  193.          done
  194.     else
  195.         for LOCALE in `/bin/ls ${MANPAGEDIR} | grep -v ^man[1-9]`
  196.          do
  197.           if [ ! "`grep -x ^${LOCALE} /etc/locale.nopurge`" ] && \
  198.              [ "`grep -x ^${LOCALE} ${LOCALELIST}`" ]; then
  199.             if [ -d ${MANPAGEDIR}/${LOCALE} ]; then
  200.                 /bin/rm -f `find ${MANPAGEDIR}/${LOCALE} -type f`
  201.             fi
  202.           fi
  203.          done
  204.     fi
  205.  
  206.     if [ "$SHOWFREEDSPACE" = "enabled" ]; then
  207.         MANAFTER=$(df -P $MANPAGEDIR | awk '{if ( NR==2 ) { print $3 }}')
  208.     MANSUM=$(($MANBEFORE - $MANAFTER))
  209.         MANTOTAL=$(($MANTOTAL + $MANSUM))
  210.     if [ ! $MANBEFORE = $MANAFTER ]; then
  211.             einfo "localepurge: Disk space freed in $MANPAGEDIR: ${BOLD}"$MANSUM"K${NORMAL}"
  212.         fi
  213.     fi
  214. fi
  215. }
  216.  
  217. for folder in ${LOCALEDIRS}; do
  218.     purgelocale "$folder"
  219. done
  220.  
  221. for folder in ${MANPAGEDIRS}; do
  222.     purgeman "$folder"
  223. done
  224.  
  225. # Calculating and reporting total disk space freed:
  226.  
  227. if [ "$SHOWFREEDSPACE" = "enabled" ]; then
  228.     if [ $MANTOTAL ] && [ $LOCALETOTAL ]; then
  229.         if [ ! $MANBEFORE = $MANAFTER ] && [ ! $LOCALEBEFORE = $LOCALEAFTER ]; then
  230.             echo ""
  231.             einfo "Total disk space freed by localepurge: ${BOLD}"$(($LOCALETOTAL + $MANTOTAL))"K${NORMAL}"
  232.             echo ""
  233.         fi
  234.     fi
  235. fi
  236.